﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Common.Web;
using CSP.Model.CSP;
using CSP.Bll;
using CSP.Model.CSPBBS;
using CSP.Web.Master;
using CSP.Web.UserControls;
using CSP.Model.CSPEnum;

namespace CSP.Web.MyHome.Account
{
    public partial class Management : CSPMyHome
    {
        private string _userName = "";

        private string _regDate = "";

        private string _authenticationTypeCNName = "未认证";

        private string _authenticationTypeStyle = "";

        private string _email = "";

        private string _mobile = "";

        #region 属性




        /// <summary>
        /// 用户名
        /// </summary>
        protected string UserName
        {
            get { return _userName; }
        }

        /// <summary>
        /// 注册时间
        /// </summary>
        protected string RegDate
        {
            get { return _regDate; }
        }

        /// <summary>
        /// 认证类型 中文名称
        /// </summary>
        protected string AuthenticationTypeCNName
        {
            get { return _authenticationTypeCNName; }
        }

        /// <summary>
        /// 认证样式
        /// </summary>
        protected string AuthenticationTypeStyle
        {
            get { return _authenticationTypeStyle; }
        }

        /// <summary>
        /// Email
        /// </summary>
        protected string Email
        {
            get { return _email; }
        }

        /// <summary>
        /// 移动电话
        /// </summary>
        protected string Mobile
        {
            get { return _mobile; }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

            U_SynthesizeUserCredit.UserName = this.UserProvider.UserName;
            ((HomeMaster)Master).SelectedNavigationLink = MyHomeLeftNavigationLink.Accoun;
            if (!IsPostBack)
            {
                SetUserInfo();
            }
        }



        private void SetUserInfo()
        {
            Member member = UserProvider.GetUserInfo(true);
            if (member != null)
            {
                _userName = member.UserName;
                _regDate = member.RegDate.ToString("yyyy-MM-dd");

                _email = member.Email;
                if (member.MemberProfile != null)
                {
                    _mobile = member.MemberProfile.Mobile;
                }


                //初始化认证
                if (member.UserBasic != null)
                {
                    int personalAuthentication = Convert.ToInt32(member.UserBasic.PersonalAuthentication);
                    int enterpriseAuthentication = Convert.ToInt32(member.UserBasic.EnterpriseAuthentication);
                    _authenticationTypeCNName = GetCNNameByAuthentication(personalAuthentication, enterpriseAuthentication);
                    _authenticationTypeStyle = GetStyleByAuthentication(personalAuthentication, enterpriseAuthentication);
                }
            }

        }

        /// <summary>
        /// 根据认证类型和认证状态获取 当前认证名称
        /// </summary>
        /// <param name="personalAuthentication"></param>
        /// <param name="enterpriseAuthentication"></param>
        /// <returns></returns>
        protected string GetCNNameByAuthentication(int personalAuthentication, int enterpriseAuthentication)
        {
            if ((AuthenticationStatus)enterpriseAuthentication == AuthenticationStatus.Accomplish)
            {
                return "企业认证";
            }

            if ((AuthenticationStatus)personalAuthentication == AuthenticationStatus.Accomplish)
            {
                return "个人认证";
            }

            return "未认证";
        }

        /// <summary>
        /// 获取样式根据企业认证和个人认证 状态
        /// </summary>
        /// <param name="personalAuthentication"></param>
        /// <param name="enterpriseAuthentication"></param>
        /// <returns></returns>
        protected string GetStyleByAuthentication(int personalAuthentication, int enterpriseAuthentication)
        {
            //企业认证
            if ((AuthenticationStatus)enterpriseAuthentication == AuthenticationStatus.Accomplish)
            {
                return "ui-indentification-enterprise";
            }

            //个人认证
            else if ((AuthenticationStatus)personalAuthentication == AuthenticationStatus.Accomplish)
            {
                return "ui-indentification-personal";
            }
            else
            {
                return "";
            }
        }

    }
}